package com.itheima.Synchronized2;

public class Account {
    private String cardId;
    private double money;
        //加锁方法二：同步方法
    public  synchronized    void getmoney(double money) {
        Thread t = Thread.currentThread();
        System.out.println(t.getName() + "正在取钱：。。。。。");

        if (this.money >= money) {
            this.money -= money;
            System.out.println(t.getName() + "取钱成功！余额为：" + this.money );
        } else {
            System.out.println(t.getName() + "取钱失败！余额不足！");
        }
    }


    public Account() {
    }

    public Account(String cardId, double money) {
        this.cardId = cardId;
        this.money = money;
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "Account{" +
                "cardId='" + cardId + '\'' +
                ", money=" + money +
                '}';
    }
}

